package com.shitou.shitoucart.controller;


import com.shitou.shitoucart.entity.MemberCartEntity;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shitou.shitoucart.service.MemberCartService;

import java.util.Arrays;
import java.util.Map;


/**
 * 购物车-cat
 *
 * @author shitouren
 * @email 3076767823@qq.com
 * @date 2023-03-20 00:56:24
 */
@RestController
@RequestMapping("shitoucart/membercart")
public class MemberCartController {
    @Autowired
    private MemberCartService memberCartService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = memberCartService.queryPage(params);

        return RespBean.success().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public RespBean info(@PathVariable("attrId") Long attrId){
        MemberCartEntity attr = memberCartService.getById(attrId);

        return RespBean.success().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody MemberCartEntity attr){
        memberCartService.save(attr);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody MemberCartEntity attr){
        memberCartService.updateById(attr);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] attrIds){
        memberCartService.removeByIds(Arrays.asList(attrIds));

        return RespBean.success();
    }

}
